unit UServerContainer;

interface

uses
  SysUtils, Classes, IniFiles,
  DSTCPServerTransport, DSServer, DSCommonServer;

type
  TServerContainer = class(TDataModule)
    DSServer1: TDSServer;
    DSTCPServerTransport1: TDSTCPServerTransport;
    DSServerClass1: TDSServerClass;
    procedure DSServerClass1GetClass(DSServerClass: TDSServerClass;
      var PersistentClass: TPersistentClass);
    procedure DataModuleCreate(Sender: TObject);
  private
    { Private declarations }
  public
  end;

var
  ServerContainer: TServerContainer;

function StartService: Boolean;
procedure StopService;
function GetServiceStarted: Boolean;

implementation

uses UServerMethods, UGlobalVar;

{$R *.dfm}

function StartService: Boolean;
begin
  try
    if not Assigned(ServerContainer) then
      ServerContainer := TServerContainer.Create(nil);
    with ServerContainer do
    begin
      if not DSServer1.Started then
        DSServer1.Start;
      Result := DSServer1.Started;
    end;
  except
    Result := False;
  end;
end;

procedure StopService;
begin
  if Assigned(ServerContainer) then
  begin
    if ServerContainer.DSServer1.Started then
      ServerContainer.DSServer1.Stop;
    FreeAndNil(ServerContainer);
  end;
end;

function GetServiceStarted: Boolean;
begin
  if Assigned(ServerContainer) then
    Result := ServerContainer.DSServer1.Started
  else
    Result := False;
end;

procedure TServerContainer.DataModuleCreate(Sender: TObject);
var
  lIni: TIniFile;
  lPort: Integer;
begin
  lIni := TIniFile.Create(GLB.AppPath + 'config\telnet.ini');
  try
    lPort := lIni.ReadInteger('TCPTransport', 'Port', 211);
    DSTCPServerTransport1.Port := lPort;
  finally
    lIni.Free;
  end;
end;

procedure TServerContainer.DSServerClass1GetClass(
  DSServerClass: TDSServerClass; var PersistentClass: TPersistentClass);
begin
  PersistentClass := UServerMethods.TServerMethods;
end;

end.




